package cn.xxstudy.visitshop.ui.activity.login

import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope
import cn.xxstudy.visitshop.R
import cn.xxstudy.visitshop.ui.activity.login.viewmodel.LoginViewModel
import cn.xxstudy.visitshop.ui.activity.main.MainActivity
import cn.xxstudy.visitshop.ui.activity.register.RegisterActivity
import kotlinx.android.synthetic.main.activity_login.*
import kotlinx.coroutines.launch

/**
 * @author ：DELL on 2021/3/23 .
 * @packages ：cn.xxstudy.visitshop.ui.activity.login .
 * TODO:登录
 */
class LoginActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_login)
        val login = ViewModelProvider(this).get(LoginViewModel::class.java)
        login.loginSuccess.observe(this, Observer {
//            startActivity(Intent(this, MainActivity::class.java))
//            finish()
        })

        registerBtn.setOnClickListener {
            startActivity(Intent(this, RegisterActivity::class.java))
        }

        login.loginFail.observe(this, Observer {
            Toast.makeText(this, it, Toast.LENGTH_SHORT).show()
        })

        loginBtn.setOnClickListener {
            login.login(userEdit.text.toString(), pwdEdit.text.toString())
        }


    }

}